package com.sghd.charge.module.payment.iospay.model;

import java.math.BigDecimal;

/**
 * @author frank
 * @date 2019-03-07 14:21
 * @desc
 **/
public class VerifyInfo {
    private int code;
    private String msg;
    private String productId;
    private int quantity;
    private String transactionId;
    private int totalFee;

    public static VerifyInfo SUCCESS(String productId, String quantity, String transactionId) {
        VerifyInfo info = new VerifyInfo();
        info.productId = productId;
        info.quantity = Integer.parseInt(quantity);
        info.transactionId = transactionId;
        int money = getMondy(productId);
        BigDecimal fee = BigDecimal.valueOf(money);
        fee = fee.movePointRight(2);
        info.totalFee = fee.intValue();
        return info;
    }

    public static VerifyInfo ERROR(int code, String msg) {
        VerifyInfo info = new VerifyInfo();
        info.code = code;
        info.msg = msg;
        return info;
    }

    public static int getMondy(String productId) {
        //产品id第一位代表类型，后面的代表实际金额
        String mondy = productId.substring(1);
        return Integer.parseInt(mondy);
    }

    public boolean success() {
        return code == 0;
    }

    public boolean fail() {
        return code != 0;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(String transactionId) {
        this.transactionId = transactionId;
    }

    public int getTotalFee() {
        return totalFee;
    }

    public void setTotalFee(int totalFee) {
        this.totalFee = totalFee;
    }
}
